{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "阿里研究院\n",
    "阿里健康\n",
    "阿里巴巴商学院\n",
    "阿里数据\n",
    "\n",
    "腾讯金融科技\n",
    "腾讯研究院\n",
    "腾讯媒体研究院\n",
    "腾讯云启研究院\n",
    "酷鹅用户研究院\n",
    "'''\n",
    "公众号 = \"蚂蚁金服科技\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "fn = { \"output\" : { \"公众号_htm_snippets\": \"data_raw_src/公众号_htm_snippets_{公众号}.tsv\",\n",
    "                    \"公众号_df\": \"data_raw_src/公众号_df_{公众号}.tsv\",\n",
    "                    \"公众号_xlsx\": \"data_sets/公众号_url_{公众号}.xlsx\" } \\\n",
    "      }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（requests）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-70-f42f706dff10>, line 15)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-70-f42f706dff10>\"\u001b[1;36m, line \u001b[1;32m15\u001b[0m\n\u001b[1;33m    data = {\u001b[0m\n\u001b[1;37m       ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 目标url\n",
    "\n",
    "import time\n",
    "import requests\n",
    "import pandas as pd\n",
    "import csv\n",
    "\n",
    "\n",
    "url = \"https://mp.weixin.qq.com/cgi-bin/appmsg\"\n",
    "\n",
    "# 使用Cookie，跳过登陆操作\n",
    "headers = {\n",
    "  \"Cookie\": \"tvfe_boss_uuid=64bc2f98643c380f; pgv_pvid=9065773344; ua_id=0XqXYDKdr7UxlEvSAAAAAA0xNKV0KCdP5yNu7A-SnQg=; pgv_pvi=6620257280; RK=apLkKn5pUk; ptcz=db48cbfce01ceceb7c33473e393b1ff0381ddae07ab11fc6808d26d28296e0b5; _ga=GA1.2.1477007206.1546864108; o_cookie=775773253; pac_uid=1_775773253; mm_lang=zh_CN; gr_user_id=eca6075f-e120-4964-83f8-03de78fdff81; wxuin=67566814658649; openid2ticket_oEaky5mlfXXM250Uaz-KUOpF84OU=UVL10cIEt9L2n8KMP0itAM4Nqj+Vkb2mxwaTXIc/U+o=; XWINDEXGREY=0; openid2ticket_oYVMp44dNCdT3oqk74Grc9B59Qaw=iQs07T6Miwa8Jy02Aq7WarVKI1ON9s89XgWTfdbcBrY=; openid2ticket_opNxEuB8Z7-VjX_H_xu7ZEfzxkyU=KKQld2Oe9SDNw/ascO1x6XeqOyd7HQzNvWo4NNzZYfc=; rand_info=CAESIFO8r+wQdzlT1hs3Foe0VBvLQdnTCQjAy2l3gaEtR7Ry; slave_bizuin=3091520676; data_bizuin=3091520676; bizuin=3091520676; data_ticket=5RWtGZCJsiKN4YQcj86DqI6JfwGKoZz4XdnBPif6zCKyCSL/T0UjvP3WKYPOK8lv; slave_sid=VHNlY1Jwa2hOV3VGSEtsV0VfbG1EZU5UOWhYWEt2SThsSXJQRGM2ZEczVlFfdHc2Ujk2ZTdiNWdrcWs0TWJTSWRhY2syQ3EzZGQyYVJlNF9WcEp3Z3pLR3k4aW8xTzdkWGx5aTQyQVpRRmltV2RpRUdhbFRZd2p4MVpLNm4yR3l3OTRKdHRiQXBXUEJ4TExF; slave_user=gh_6781679f1e20; xid=42c5c3182fbee92f1d59f3c5b65050b3\",\n",
    "  \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36\"\n",
    "data = {\n",
    "    \"action\": \"list_ex\",\n",
    "    \"begin\":\"0\",\n",
    "    \"count\": \"5\",\n",
    "    \"fakeid\": \"MzI1ODcxNzMxMQ==\",\n",
    "    \"type\": \"9\",\n",
    "    \"token\":\"922367858\",\n",
    "    \"query\":\"\",\n",
    "    \"lang\": \"zh_CN\",\n",
    "    \"f\": \"json\",\n",
    "    \"ajax\":\"1\",\n",
    "}\n",
    "\n",
    "\n",
    "\n",
    "content_list=[]\n",
    "\n",
    "for i in range(5):\n",
    "    data[\"begin\"] = i*5\n",
    "    print(data[\"begin\"])\n",
    "    time.sleep(3)\n",
    "    # 使用get方法进行提交\n",
    "    content_json = requests.get(url, headers=headers, params=data).json()\n",
    "#     print(content_json)\n",
    "    # 返回了一个json，里面是每一页的数据\n",
    "    for item in content_json[\"app_msg_list\"]:\n",
    "    # 提取每页文章的标题及对应的url\n",
    "        items = []\n",
    "        items.append(item[\"title\"])\n",
    "        items.append(item[\"link\"])\n",
    "        items.append(item[\"create_time\"])\n",
    "        content_list.append(items)\n",
    "\n",
    "\n",
    "name=['title','link','create_time']\n",
    "test=pd.DataFrame(columns=name,data=content_list)\n",
    "with pd.ExcelWriter(fn[\"output\"][\"传媒实习那些事儿_xlsx\"].format(公众号=\"传媒实习那些事儿_requests\")) as writer:\n",
    "    test.to_excel(writer)\n",
    "\n",
    "# test.to_csv(\"../微信公众号爬虫_zhichao/南方周末.csv\",mode='a',encoding='utf-8')\n",
    "# print(\"保存成功\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（selenium）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from lxml.html import fromstring\n",
    "import time\n",
    "from random import random\n",
    "\n",
    "# when selenium main_content is used\n",
    "# Parses an HTML document from a string constant.  Returns the root nood\n",
    "# root = fromstring(df.loc[1,\"html_snippets\"]) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用Selenium\n",
    "* 要更改 opts.binary_location 至自己本地的Chrome浏览器，建议portable\n",
    "* Chrome浏览器 和 chromedriver.exe要同版本号到小数后一位\n",
    "* 要确保可以 开启浏览器机器人\n",
    "* 要确保浏览器机器人 可以打开网页 driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\1\\anaconda3\\lib\\site-packages\\ipykernel_launcher.py:18: DeprecationWarning: use options instead of chrome_options\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.desired_capabilities import DesiredCapabilities\n",
    "\n",
    "#caps=dict()\n",
    "#caps[\"pageLoadStrategy\"] = \"none\"   # Do not wait for full page load\n",
    "\n",
    "opts = webdriver.ChromeOptions()\n",
    "opts.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错\n",
    "opts.add_argument('window-size=1920x3000') #指定浏览器分辨率\n",
    "opts.add_argument('--disable-gpu') #谷歌文档提到需要加上一这个属性来规避bug\n",
    "opts.add_argument('--hide-scrollbars') #隐藏滚动条, 应对些特殊页面\n",
    "#opts.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度\n",
    "#opts.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败\n",
    "\n",
    "opts.binary_location = r\"C:\\\\Users\\\\1\\\\AppData\\\\Local\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe\" #\"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "\n",
    "# \"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "driver = webdriver.Chrome( chrome_options = opts) #desired_capabilities=caps,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 填表登入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "selenium 的定位方法\n",
    "* find_element_by_id &ensp;&ensp;&ensp;  根据标签id定位\n",
    "* find_element_by_name   &ensp;&ensp;&ensp; 根据标签的name定位\n",
    "* find_element_by_xpath  &ensp;&ensp;&ensp; 根据xpath定位\n",
    "* find_element_by_link_text  &ensp;&ensp;&ensp; 通过文字链接来定位元素\n",
    "* find_element_by_partial_link_text  &ensp;&ensp;&ensp;  通过文字链接来定位元素\n",
    "* find_element_by_tag_name  &ensp;&ensp;&ensp;  根据标签的名字定位\n",
    "* find_element_by_class_name  &ensp;&ensp;&ensp; 通过class name 定位\n",
    "* find_element_by_css_selector  &ensp;&ensp;&ensp;  根据元素属性来定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "ename": "ElementNotInteractableException",
     "evalue": "Message: element not interactable\n  (Session info: chrome=81.0.4044.138)\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mElementNotInteractableException\u001b[0m           Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-7-b65352e105df>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mpayload\u001b[0m \u001b[1;33m=\u001b[0m  \u001b[1;33m{\u001b[0m\u001b[1;34m\"account\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m\"M15219611199@163.com\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"password\"\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m\"sehun0412\"\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;31m# payload =  {\"account\": \"NFUHacks@163.com\", \"password\": \"NFU706947580\"}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mdriver\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfind_element_by_xpath\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'//div[@class=\"login__type__container login__type__container__scan\"]/a'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclick\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py\u001b[0m in \u001b[0;36mclick\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m     78\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mclick\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     79\u001b[0m         \u001b[1;34m\"\"\"Clicks the element.\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 80\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_execute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCommand\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCLICK_ELEMENT\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     81\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     82\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0msubmit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py\u001b[0m in \u001b[0;36m_execute\u001b[1;34m(self, command, params)\u001b[0m\n\u001b[0;32m    631\u001b[0m             \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    632\u001b[0m         \u001b[0mparams\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'id'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 633\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommand\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    634\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    635\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mfind_element\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mby\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mBy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mID\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self, driver_command, params)\u001b[0m\n\u001b[0;32m    319\u001b[0m         \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommand_executor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdriver_command\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    320\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 321\u001b[1;33m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merror_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_response\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    322\u001b[0m             response['value'] = self._unwrap_value(\n\u001b[0;32m    323\u001b[0m                 response.get('value', None))\n",
      "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py\u001b[0m in \u001b[0;36mcheck_response\u001b[1;34m(self, response)\u001b[0m\n\u001b[0;32m    240\u001b[0m                 \u001b[0malert_text\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'alert'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'text'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    241\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0malert_text\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 242\u001b[1;33m         \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    243\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    244\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_value_or_default\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mElementNotInteractableException\u001b[0m: Message: element not interactable\n  (Session info: chrome=81.0.4044.138)\n"
     ]
    }
   ],
   "source": [
    "payload =  {\"account\": \"M15219611199@163.com\", \"password\": \"sehun0412\"}\n",
    "# payload =  {\"account\": \"NFUHacks@163.com\", \"password\": \"NFU706947580\"}\n",
    "driver.find_element_by_xpath('//div[@class=\"login__type__container login__type__container__scan\"]/a').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "WebDriver 常用方法：\n",
    "* clear()清除文本\n",
    "* send_keys(values)模拟按键输入\n",
    "* click()模拟点击\n",
    "* submit模拟提交"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').send_keys(payload['account'])\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').send_keys(payload['password'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//div[@class=\"login_btn_panel\"]/a').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 点选单"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其他常用方法\n",
    "* size：返回元素的尺寸\n",
    "* text：获取元素的文本\n",
    "* get_attribute：获取属性值  &ensp;&ensp;&ensp; get_attribute('innerHTML')获取元素内的全部HTML\n",
    "* is_displayed()：设置该元素用户是否可见"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'展开'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//a[@id=\"m_open\"]')\n",
    "element.click()\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.execute_script(\"window.scrollTo(0,document.body.scrollHeight)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://mp.weixin.qq.com/cgi-bin/appmsg?begin=0&count=10&t=media/appmsg_list&type=10&action=list&token=1833585316&lang=zh_CN'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//li[@title[contains(.,\"素材管理\")]]/a') \n",
    "# main_content = element.get_attribute('innerHTML')\n",
    "# main_content\n",
    "url2= element.get_attribute(\"href\")\n",
    "url2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(url2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 新建图文消息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"新建图文消息\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "main_content\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['CDwindow-A8238326E8352BB70BE06A6974D35341', 'CDwindow-980EB5FCF344439C4EC895C4BC55E03E', 'CDwindow-6ACCC17B14DEA446533131B33A3D2425']\n"
     ]
    }
   ],
   "source": [
    "print (driver.window_handles)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新建图文消息开了另一分视窗，所以要切换 switch_to \n",
    "driver.switch_to.window(driver.window_handles[-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 超链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                超链接              \n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"超链接\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "选择其他公众号\n"
     ]
    }
   ],
   "source": [
    "# 点 选择其他公众号\n",
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"选择其他公众号\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').clear()\n",
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').send_keys('传媒实习那些事儿')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<div class=\"weui-desktop-icon weui-desktop-icon__inputSearch weui-desktop-icon__small\"><!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.33 10.007l4.273 4.273a.502.502 0 0 1 .005.709l-.585.584a.499.499 0 0 1-.709-.004L10.046 11.3a6.278 6.278 0 1 1 1.284-1.294zm.012-3.729a5.063 5.063 0 1 0-10.127 0 5.063 5.063 0 0 0 10.127 0z\"></path></svg> <!----> <!----> <!----> <!----></div>\n"
     ]
    }
   ],
   "source": [
    "# 点放大镜搜\n",
    "element = driver.find_element_by_xpath('//button[@class=\"weui-desktop-icon-btn weui-desktop-search__btn\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/lMnpYygAUicHNkBbgWdmsS9An4PnHBfNzNHs2p9IW7AljF42P8kZibc7bxzv8mlXUX3yuicPdxgh69eQvUcic9eYeA/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">传媒实习那些事儿</strong> <i class=\"inner_link_account_wechat\">微信号：media-practice</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/ocaYtPBfeskcSFO9aGnIukE2uWMibbsDah4TvhEHnk7lUwLrCLON0af5Nibr8icozZwMLGQyUDvk8aib2vAViclquUw/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">传媒职场HR</strong> <i class=\"inner_link_account_wechat\">微信号：workrely-hr</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/yNyfdDYdmtU9sG2PaAUl3ZJicm8FpD7qseOvJv13fIxvQ4NsiawF5QUDWUtiaOibcDWwtJwu44GaMr4T0Eco01R54Q/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">传媒实习僧</strong> <i class=\"inner_link_account_wechat\">微信号：cucnzc2014</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/GNC7d8ouqZqqUpTwHnicgrWqIy2KiaRc6uflGW7uEPumoxibD7bFeibLR6uRXxtrYibt581gXRoU8RMBcVp7mw4Fjuw/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">HOT匠传媒招聘</strong> <i class=\"inner_link_account_wechat\">微信号：rentuila</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li><li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/tpAss4OYVwn2lBhSMcAic4Liajp7vExB4PIWQcB2Ch9BlNGAr2B3DhpdPYe5YoEp2uQrnBE792rbwOdnicdhSnQ0Q/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">网易传媒招聘</strong> <i class=\"inner_link_account_wechat\">微信号：wycmzhaopin</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">服务号</div></li>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "公众号SERP = main_content\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 解析\n",
    "root = fromstring(公众号SERP) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "主 = root.xpath('//li[@class=\"inner_link_account_item\"]')\n",
    "\n",
    "account_list = []\n",
    "for e in 主:\n",
    "    account_nickname = e.xpath('./div/strong[@class=\"inner_link_account_nickname\"]')[0].text\n",
    "    account_wechat = e.xpath('./div/i[@class=\"inner_link_account_wechat\"]')[0].text\n",
    "    account_img = e.xpath('./div/img/@src')[0]\n",
    "    account = {\"nickname\": account_nickname, \"wechat\": account_wechat, \"img\": account_img,}\n",
    "    account_list.append(account)\n",
    "\n",
    "df_account = pd.DataFrame(account_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>nickname</th>\n",
       "      <th>wechat</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>传媒实习那些事儿</td>\n",
       "      <td>微信号：media-practice</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/lMnpYygAUicHNkB...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>传媒职场HR</td>\n",
       "      <td>微信号：workrely-hr</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/ocaYtPBfeskcSFO...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>传媒实习僧</td>\n",
       "      <td>微信号：cucnzc2014</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/yNyfdDYdmtU9sG2...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HOT匠传媒招聘</td>\n",
       "      <td>微信号：rentuila</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/GNC7d8ouqZqqUpT...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>网易传媒招聘</td>\n",
       "      <td>微信号：wycmzhaopin</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/tpAss4OYVwn2lBh...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   nickname              wechat  \\\n",
       "0  传媒实习那些事儿  微信号：media-practice   \n",
       "1    传媒职场HR     微信号：workrely-hr   \n",
       "2     传媒实习僧      微信号：cucnzc2014   \n",
       "3  HOT匠传媒招聘        微信号：rentuila   \n",
       "4    网易传媒招聘     微信号：wycmzhaopin   \n",
       "\n",
       "                                                 img  \n",
       "0  http://mmbiz.qpic.cn/mmbiz_png/lMnpYygAUicHNkB...  \n",
       "1  http://mmbiz.qpic.cn/mmbiz_png/ocaYtPBfeskcSFO...  \n",
       "2  http://mmbiz.qpic.cn/mmbiz_png/yNyfdDYdmtU9sG2...  \n",
       "3  http://mmbiz.qpic.cn/mmbiz_png/GNC7d8ouqZqqUpT...  \n",
       "4  http://mmbiz.qpic.cn/mmbiz_png/tpAss4OYVwn2lBh...  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/lMnpYygAUicHNkBbgWdmsS9An4PnHBfNzNHs2p9IW7AljF42P8kZibc7bxzv8mlXUX3yuicPdxgh69eQvUcic9eYeA/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">传媒实习那些事儿</strong> <i class=\"inner_link_account_wechat\">微信号：media-practice</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]/li')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n跳转_input = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/input\\')\\n跳转_a = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/a\\')\\n跳转_input.clear()\\n跳转_input.send_keys(2)\\n跳转_a.click()\\n'"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 跳转testing\n",
    "'''\n",
    "跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "跳转_input.clear()\n",
    "跳转_input.send_keys(2)\n",
    "跳转_a.click()\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 79]\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 跳转上限\n",
    "l_e = driver.find_elements_by_xpath('//label[@class=\"weui-desktop-pagination__num\"]')\n",
    "l_e_int  = [int(x.text) for x in l_e] \n",
    "print (l_e_int)\n",
    "print (l_e_int[0]==l_e_int[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79]\n"
     ]
    }
   ],
   "source": [
    "pages = list(range(l_e_int[0],l_e_int[-1]+1 ))\n",
    "#print(pages[0:2])\n",
    "pages = list(range(1,l_e_int[-1]+1 ))\n",
    "print(pages)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 循环/遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "# global varialbes \n",
    "html_raw = dict()\n",
    "main_content =\"\"\n",
    "element = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "def process_pages (pages):\n",
    "    for p in pages:\n",
    "        print (p,end='\\t')\n",
    "\n",
    "        跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "        跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "        跳转_input.clear()\n",
    "        跳转_input.send_keys(p)\n",
    "        跳转_a.click()\n",
    "\n",
    "        time.sleep(35+100*random())\n",
    "\n",
    "        element = driver.find_element_by_xpath('//div[@class=\"inner_link_article_list\"]')\n",
    "        main_content = element.get_attribute('innerHTML')\n",
    "        #print(main_content)\n",
    "        html_raw[p] = main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\t27\t28\t29\t30\t31\t32\t33\t34\t35\t36\t37\t38\t39\t40\t41\t42\t43\t44\t45\t46\t47\t48\t49\t50\t51\t52\t53\t54\t55\t56\t57\t58\t59\t60\t61\t62\t63\t64\t65\t66\t67\t68\t69\t70\t71\t72\t73\t74\t75\t76\t77\t78\t79\t"
     ]
    }
   ],
   "source": [
    "process_pages(pages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>79 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        html_snippets\n",
       "1   <div><label class=\"inner_link_article_item\"><s...\n",
       "2   <div><label class=\"inner_link_article_item\"><s...\n",
       "3   <div><label class=\"inner_link_article_item\"><s...\n",
       "4   <div><label class=\"inner_link_article_item\"><s...\n",
       "5   <div><label class=\"inner_link_article_item\"><s...\n",
       "..                                                ...\n",
       "75  <div><label class=\"inner_link_article_item\"><s...\n",
       "76  <div><label class=\"inner_link_article_item\"><s...\n",
       "77  <div><label class=\"inner_link_article_item\"><s...\n",
       "78  <div><label class=\"inner_link_article_item\"><s...\n",
       "79  <div><label class=\"inner_link_article_item\"><s...\n",
       "\n",
       "[79 rows x 1 columns]"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([html_raw]).T\n",
    "df.columns = [\"html_snippets\"]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stored 'html_raw' (dict)\n"
     ]
    }
   ],
   "source": [
    "%store html_raw\n",
    "import pickle \n",
    "filehandler = open(\"html_raw\", 'wb') \n",
    "pickle.dump(html_raw, filehandler)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "78\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        html_snippets\n",
       "12  <div><label class=\"inner_link_article_item\"><s..."
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_out = df[~df.duplicated()]\n",
    "print (len(df_out))\n",
    "df[df.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[12]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[12]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "try_again = list(df[df.duplicated()].index)\n",
    "print(try_again)\n",
    "try_again = try_again + list (set(pages).difference(set(df.index.values)))\n",
    "try_again"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 暂存档"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = fn [\"output\"] [\"公众号_htm_snippets\"] \n",
    "df_out.to_excel(\"传媒实习那些事儿excel.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38,28,22,34,34,24,27,35,33,25,29,28,24,26,32,23,23,33,22,19,18,19,33,34,28,30,36,33,34,34,29,30,30,34,25,29,32,34,28,34,32,29,26,26,26,25,27,26,20,23,23,17,19,24,24,18,21,20,22,23,20,20,18,17,17,15,16,15,18,19,16,15,14,15,17,14,18,16,9,"
     ]
    }
   ],
   "source": [
    "def parse_html_snippets(_snippet_):\n",
    "    root = fromstring(_snippet_) \n",
    "    title = [x.text for x in root.xpath('//div[@class=\"inner_link_article_title\"]')]\n",
    "    create_time = [x.text for x in root.xpath('//div[@class=\"inner_link_article_date\"]')]\n",
    "    link = [x for x in root.xpath('//a/@href')]\n",
    "    _df_ = pd.DataFrame({\"title\":title, \"create_time\": create_time, \"link\":link})\n",
    "    return(_df_)\n",
    "    \n",
    "l_df = []\n",
    "for p in pages:\n",
    "    _df_ = parse_html_snippets(df.loc[p,\"html_snippets\"])\n",
    "    print (len(_df_), end=\",\")\n",
    "    l_df.append(_df_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>传媒实习 · 央媒 | 人民网「北京」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>传媒实习 · 国际 | 联合国难民署招募新闻与传播实习生</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>传媒实习 · 运营 | 太平洋网络「广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>传媒实习 · 多岗 | 《密室大逃脱》「湖南」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>传媒实习 · 公关 | 万博宣伟「上海」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>传媒实习 · 美妆 | 《ELLE》「北京」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>传媒实习 · 多岗 | 阿里巴巴「远程/浙江」</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>传媒实习 · 雅思 | 无套路，不转发，添加好友即可领取的雅思资料，趁休息的日子提高自我吧~</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>传媒实习 · 运营 | 腾讯「北京」</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             title create_time  \\\n",
       "0                  传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」  2020-05-15   \n",
       "1                              传媒实习 · 央媒 | 人民网「北京」  2020-05-15   \n",
       "2                 传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」  2020-05-15   \n",
       "3                     传媒实习 · 国际 | 联合国难民署招募新闻与传播实习生  2020-05-15   \n",
       "4                            传媒实习 · 运营 | 太平洋网络「广东」  2020-05-15   \n",
       "5                          传媒实习 · 多岗 | 《密室大逃脱》「湖南」  2020-05-15   \n",
       "6                             传媒实习 · 公关 | 万博宣伟「上海」  2020-05-15   \n",
       "7                           传媒实习 · 美妆 | 《ELLE》「北京」  2020-05-15   \n",
       "8                          传媒实习 · 多岗 | 阿里巴巴「远程/浙江」  2020-05-14   \n",
       "9   传媒实习 · 雅思 | 无套路，不转发，添加好友即可领取的雅思资料，趁休息的日子提高自我吧~  2020-05-14   \n",
       "10                              传媒实习 · 运营 | 腾讯「北京」  2020-05-14   \n",
       "\n",
       "                                                 link  \n",
       "0   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "2   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "3   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "4   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "5   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "6   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "7   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "8   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "9   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "10  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  "
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out = pd.concat(l_df).reset_index(drop=True)\n",
    "df_url_out.loc[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1938</th>\n",
       "      <td>传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1939</th>\n",
       "      <td>传媒实习 · 广东 | 广州日报</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1940</th>\n",
       "      <td>传媒实习 · 上海 | 大鹏工作室、香蕉娱乐</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1941</th>\n",
       "      <td>传媒实习 · 浙江 | 网易</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1942</th>\n",
       "      <td>传媒实习 · 湖北 | 良品铺子</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title create_time  \\\n",
       "1938  传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...  2018-07-10   \n",
       "1939                                   传媒实习 · 广东 | 广州日报  2018-07-10   \n",
       "1940                             传媒实习 · 上海 | 大鹏工作室、香蕉娱乐  2018-07-10   \n",
       "1941                                     传媒实习 · 浙江 | 网易  2018-07-10   \n",
       "1942                                   传媒实习 · 湖北 | 良品铺子  2018-07-10   \n",
       "\n",
       "                                                   link  \n",
       "1938  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1939  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1940  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1941  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1942  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  "
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out.tail(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>value</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>传媒实习 · 央媒 | 人民网「北京」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>传媒实习 · 运营 | 太平洋网络「广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>传媒实习 · 多岗 | 《密室大逃脱》「湖南」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>传媒实习 · 公关 | 万博宣伟「上海」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1937</th>\n",
       "      <td>传媒实习 · 上海 |爱奇艺、SexyVC</td>\n",
       "      <td>2018-07-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1939</th>\n",
       "      <td>传媒实习 · 广东 | 广州日报</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1940</th>\n",
       "      <td>传媒实习 · 上海 | 大鹏工作室、香蕉娱乐</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1941</th>\n",
       "      <td>传媒实习 · 浙江 | 网易</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1942</th>\n",
       "      <td>传媒实习 · 湖北 | 良品铺子</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1586 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  title create_time  \\\n",
       "value                                                 \n",
       "1                   传媒实习 · 央媒 | 人民网「北京」  2020-05-15   \n",
       "2      传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」  2020-05-15   \n",
       "4                 传媒实习 · 运营 | 太平洋网络「广东」  2020-05-15   \n",
       "5               传媒实习 · 多岗 | 《密室大逃脱》「湖南」  2020-05-15   \n",
       "6                  传媒实习 · 公关 | 万博宣伟「上海」  2020-05-15   \n",
       "...                                 ...         ...   \n",
       "1937              传媒实习 · 上海 |爱奇艺、SexyVC  2018-07-19   \n",
       "1939                   传媒实习 · 广东 | 广州日报  2018-07-10   \n",
       "1940             传媒实习 · 上海 | 大鹏工作室、香蕉娱乐  2018-07-10   \n",
       "1941                     传媒实习 · 浙江 | 网易  2018-07-10   \n",
       "1942                   传媒实习 · 湖北 | 良品铺子  2018-07-10   \n",
       "\n",
       "                                                    link  \n",
       "value                                                     \n",
       "1      http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "2      http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "4      http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "5      http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "6      http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "...                                                  ...  \n",
       "1937   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1939   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1940   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1941   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1942   http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "\n",
       "[1586 rows x 3 columns]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tagging 标记\n",
    "tagging_list = [\"\",\"马化腾\", \"腾讯\", \"微众银行\",\"腾讯复星\",\"腾讯风控\",\"腾讯支付\",\"WeChat\",\"We Remit\",\\\n",
    "                \"公益日\",\"红包\",\\\n",
    "                \"腾讯财付通\",\"鹅厂\",\"QQ钱包\",\"QQ红包\",\"QQ\",\\\n",
    "                \"只有一\",\"大咖\",\"听说\",\"图片\",\"照片\",\"小编\",\\\n",
    "                \"洗钱\", \"黑产\",\"被骗\",\"腾讯安全课\",\"诈骗\", \"炒股\",\"神秘兼职\",\"神秘组织\",\\\n",
    "                \"财付通\", \"品牌\",\\\n",
    "                \"收款\",\\\n",
    "                \"报告\",\\\n",
    "                \"银行卡\",\"理财\",\"选股\",\"发票\",\"基金\",\\\n",
    "                \"区块链\",\"金融云\",\"O2O\",\"农产品\",\"家乡\",\\\n",
    "                \"数据\", \"数据赋能\", \"智能\", \"数字孪生\", \"智慧大脑\",\\\n",
    "                \"出行\",\"乘车\",\"公交\",\"乘车码\", \"智慧地铁\",\\\n",
    "                \"高峰论坛\", \"智库\",\\\n",
    "                \"央行\",\"新规\", \\\n",
    "                \"微信\", \"微信支付\", \"跨境支付\", \"移动支付\",\"非银行支付\",\"电子支付\",\\\n",
    "                \"互联网金融\", \"金融科技\",\"互联网＋\",\"互联网+金融\",\"普惠金融\",\"虚拟银行\",\\\n",
    "                \"开放\",\"生态\",\"复杂\",\"互联网思维\",\"全球合作伙伴\",\\\n",
    "                \"联合国\", \"城市\", \"粤港澳大湾区\", \"平台\", \"可持续发展\", \"未来\", \"绿色\",\\\n",
    "                \"医护\",\"防护服\",\"小时\",\"武汉\",\"危机\",\"新冠肺炎\", \"疫\", \"疫情\", \"复工\",\"停课\",\"宅经济\",\\\n",
    "                \"基建\",\"新基建\"] #overwritable\n",
    "\n",
    "v_v_list = []\n",
    "\n",
    "for tag in tagging_list:\n",
    "    index_list = df_url_out [ df_url_out.title.str.contains(tag) ].index.tolist()\n",
    "    v_v_pairs = pd.DataFrame({tag:index_list}).melt().set_index(\"value\")\n",
    "    v_v_list.append(v_v_pairs)\n",
    "\n",
    "df_cat = v_v_list[0]\n",
    "for d in v_v_list:\n",
    "    df_cat.update(d)\n",
    "    \n",
    "# 尚未标记内容\n",
    "df_url_out.loc [ df_cat.query('variable==\"\"').index ]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "df_url_out.loc[53].link"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>329</th>\n",
       "      <td>传媒实习 · 字节 | 福利超好的字节跳动招人了，投！</td>\n",
       "      <td>2020-03-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>330</th>\n",
       "      <td>传媒实习 ·  公关 | 明思力公关、万博宣伟（base北京）</td>\n",
       "      <td>2020-03-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>331</th>\n",
       "      <td>传媒实习 · 北京 | 搜狐娱乐</td>\n",
       "      <td>2020-03-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>332</th>\n",
       "      <td>传媒实习 · 多地 | 小红书</td>\n",
       "      <td>2020-03-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>333</th>\n",
       "      <td>传媒实习 · 北京 | 网易哒哒</td>\n",
       "      <td>2020-03-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>334</th>\n",
       "      <td>传媒招聘 · 字节 | 字节跳动</td>\n",
       "      <td>2020-03-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>335</th>\n",
       "      <td>传媒实习 · 蚂蚁 | 蚂蚁金服</td>\n",
       "      <td>2020-03-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>336</th>\n",
       "      <td>传媒实习 ·  央媒 | 人民网</td>\n",
       "      <td>2020-03-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>337</th>\n",
       "      <td>传媒实习 · 鹅厂  | 腾讯</td>\n",
       "      <td>2020-03-20</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>338</th>\n",
       "      <td>传媒实习 · 暑期 | 腾讯音乐</td>\n",
       "      <td>2020-03-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>339</th>\n",
       "      <td>传媒实习 · 阿里 | 阿！里！巴！巴！2020实习生招募，你还等什么？</td>\n",
       "      <td>2020-03-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>340</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯视频“嗨剧社”2020年度招新</td>\n",
       "      <td>2020-03-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>341</th>\n",
       "      <td>传媒实习 · 远程 | @大嘴鱼星访</td>\n",
       "      <td>2020-03-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>342</th>\n",
       "      <td>传媒实习 · 华为 | 华为勇敢星实习招募计划！</td>\n",
       "      <td>2020-03-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>343</th>\n",
       "      <td>传媒实习 · 大厂 | 爱奇艺（线上，无需坐班！！！）</td>\n",
       "      <td>2020-03-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>344</th>\n",
       "      <td>传媒实习 · 湖南 | 芒果TV，2020超S+级重磅综艺招聘实习生</td>\n",
       "      <td>2020-03-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>345</th>\n",
       "      <td>传媒实习 · 经纪 | 觉醒东方</td>\n",
       "      <td>2020-03-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>346</th>\n",
       "      <td>传媒实习 · 娱乐 | 搜狐娱乐</td>\n",
       "      <td>2020-03-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>347</th>\n",
       "      <td>传媒实习 · 北京 | 凤凰网财经</td>\n",
       "      <td>2020-03-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>348</th>\n",
       "      <td>传媒实习 · 上海 | 小红书</td>\n",
       "      <td>2020-03-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>349</th>\n",
       "      <td>传媒实习 · 广东 | 欢聚时代、南风窗</td>\n",
       "      <td>2020-03-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>350</th>\n",
       "      <td>传媒实习 · 多地 | 2021届同学看过来！虎牙给我投！</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>351</th>\n",
       "      <td>传媒实习 · 上海 | 灿星制作</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>352</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>353</th>\n",
       "      <td>传媒实习 · 综艺 | 欢乐传媒《高手请赐教》（北京）</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>354</th>\n",
       "      <td>传媒实习 · 大厂 | 百度（北京）、今日头条</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>355</th>\n",
       "      <td>传媒实习 · 网易 | 网易新闻（目前线上）</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>356</th>\n",
       "      <td>传媒实习  · 北京 | 罗德传播集团</td>\n",
       "      <td>2020-03-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    title create_time  \\\n",
       "329           传媒实习 · 字节 | 福利超好的字节跳动招人了，投！  2020-03-21   \n",
       "330       传媒实习 ·  公关 | 明思力公关、万博宣伟（base北京）  2020-03-21   \n",
       "331                      传媒实习 · 北京 | 搜狐娱乐  2020-03-21   \n",
       "332                       传媒实习 · 多地 | 小红书  2020-03-21   \n",
       "333                      传媒实习 · 北京 | 网易哒哒  2020-03-20   \n",
       "334                      传媒招聘 · 字节 | 字节跳动  2020-03-20   \n",
       "335                      传媒实习 · 蚂蚁 | 蚂蚁金服  2020-03-20   \n",
       "336                      传媒实习 ·  央媒 | 人民网  2020-03-20   \n",
       "337                       传媒实习 · 鹅厂  | 腾讯  2020-03-20   \n",
       "338                      传媒实习 · 暑期 | 腾讯音乐  2020-03-19   \n",
       "339  传媒实习 · 阿里 | 阿！里！巴！巴！2020实习生招募，你还等什么？  2020-03-19   \n",
       "340         传媒实习 · 鹅厂 | 腾讯视频“嗨剧社”2020年度招新  2020-03-19   \n",
       "341                    传媒实习 · 远程 | @大嘴鱼星访  2020-03-19   \n",
       "342              传媒实习 · 华为 | 华为勇敢星实习招募计划！  2020-03-19   \n",
       "343           传媒实习 · 大厂 | 爱奇艺（线上，无需坐班！！！）  2020-03-19   \n",
       "344    传媒实习 · 湖南 | 芒果TV，2020超S+级重磅综艺招聘实习生  2020-03-18   \n",
       "345                      传媒实习 · 经纪 | 觉醒东方  2020-03-18   \n",
       "346                      传媒实习 · 娱乐 | 搜狐娱乐  2020-03-18   \n",
       "347                     传媒实习 · 北京 | 凤凰网财经  2020-03-18   \n",
       "348                       传媒实习 · 上海 | 小红书  2020-03-18   \n",
       "349                  传媒实习 · 广东 | 欢聚时代、南风窗  2020-03-18   \n",
       "350         传媒实习 · 多地 | 2021届同学看过来！虎牙给我投！  2020-03-17   \n",
       "351                      传媒实习 · 上海 | 灿星制作  2020-03-17   \n",
       "352                        传媒实习 · 鹅厂 | 腾讯  2020-03-17   \n",
       "353           传媒实习 · 综艺 | 欢乐传媒《高手请赐教》（北京）  2020-03-17   \n",
       "354               传媒实习 · 大厂 | 百度（北京）、今日头条  2020-03-17   \n",
       "355                传媒实习 · 网易 | 网易新闻（目前线上）  2020-03-17   \n",
       "356                   传媒实习  · 北京 | 罗德传播集团  2020-03-17   \n",
       "\n",
       "                                                  link  \n",
       "329  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "330  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "331  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "332  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "333  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "334  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "335  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "336  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "337  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "338  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "339  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "340  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "341  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "342  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "343  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "344  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "345  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "346  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "347  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "348  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "349  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "350  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "351  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "352  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "353  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "354  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "355  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "356  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>传媒实习 · 央媒 | 人民网「北京」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>传媒实习 · 国际 | 联合国难民署招募新闻与传播实习生</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>传媒实习 · 运营 | 太平洋网络「广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1938</th>\n",
       "      <td>传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1939</th>\n",
       "      <td>传媒实习 · 广东 | 广州日报</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1940</th>\n",
       "      <td>传媒实习 · 上海 | 大鹏工作室、香蕉娱乐</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1941</th>\n",
       "      <td>传媒实习 · 浙江 | 网易</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1942</th>\n",
       "      <td>传媒实习 · 湖北 | 良品铺子</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1915 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title create_time  \\\n",
       "0                       传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」  2020-05-15   \n",
       "1                                   传媒实习 · 央媒 | 人民网「北京」  2020-05-15   \n",
       "2                      传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」  2020-05-15   \n",
       "3                          传媒实习 · 国际 | 联合国难民署招募新闻与传播实习生  2020-05-15   \n",
       "4                                 传媒实习 · 运营 | 太平洋网络「广东」  2020-05-15   \n",
       "...                                                 ...         ...   \n",
       "1938  传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...  2018-07-10   \n",
       "1939                                   传媒实习 · 广东 | 广州日报  2018-07-10   \n",
       "1940                             传媒实习 · 上海 | 大鹏工作室、香蕉娱乐  2018-07-10   \n",
       "1941                                     传媒实习 · 浙江 | 网易  2018-07-10   \n",
       "1942                                   传媒实习 · 湖北 | 良品铺子  2018-07-10   \n",
       "\n",
       "                                                   link  \n",
       "0     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "2     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "3     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "4     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "...                                                 ...  \n",
       "1938  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1939  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1940  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1941  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "1942  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...  \n",
       "\n",
       "[1915 rows x 3 columns]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[~df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "      <th>variable</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>鹅厂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>传媒实习 · 央媒 | 人民网「北京」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>传媒实习 · 国际 | 联合国难民署招募新闻与传播实习生</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>联合国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>传媒实习 · 运营 | 太平洋网络「广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1938</th>\n",
       "      <td>传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1939</th>\n",
       "      <td>传媒实习 · 广东 | 广州日报</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1940</th>\n",
       "      <td>传媒实习 · 上海 | 大鹏工作室、香蕉娱乐</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1941</th>\n",
       "      <td>传媒实习 · 浙江 | 网易</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1942</th>\n",
       "      <td>传媒实习 · 湖北 | 良品铺子</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1943 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title create_time  \\\n",
       "0                       传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」  2020-05-15   \n",
       "1                                   传媒实习 · 央媒 | 人民网「北京」  2020-05-15   \n",
       "2                      传媒实习 · 大厂 | 百度、京东、搜狐、喜马拉雅「北京/上海」  2020-05-15   \n",
       "3                          传媒实习 · 国际 | 联合国难民署招募新闻与传播实习生  2020-05-15   \n",
       "4                                 传媒实习 · 运营 | 太平洋网络「广东」  2020-05-15   \n",
       "...                                                 ...         ...   \n",
       "1938  传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...  2018-07-10   \n",
       "1939                                   传媒实习 · 广东 | 广州日报  2018-07-10   \n",
       "1940                             传媒实习 · 上海 | 大鹏工作室、香蕉娱乐  2018-07-10   \n",
       "1941                                     传媒实习 · 浙江 | 网易  2018-07-10   \n",
       "1942                                   传媒实习 · 湖北 | 良品铺子  2018-07-10   \n",
       "\n",
       "                                                   link variable  \n",
       "0     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       鹅厂  \n",
       "1     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "2     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "3     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...      联合国  \n",
       "4     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "...                                                 ...      ...  \n",
       "1938  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "1939  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "1940  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "1941  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "1942  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...     无法分类  \n",
       "\n",
       "[1943 rows x 4 columns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_o = df_url_out.join(df_cat).replace(\"\", np.nan).fillna(\"无法分类\")\n",
    "df_o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "      <th>variable</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」</td>\n",
       "      <td>2020-05-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>鹅厂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>传媒实习 · 运营 | 腾讯「北京」</td>\n",
       "      <td>2020-05-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯新闻星推榜</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>鹅厂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>传媒实习 · 鹅厂 | 腾讯多岗位「广东」</td>\n",
       "      <td>2020-05-12</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>鹅厂</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>传媒实习 · 游戏 | 腾讯游戏「广东」</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1926</th>\n",
       "      <td>传媒实习 · 北京 | CCTV《相聚中国节》、腾讯视频等。</td>\n",
       "      <td>2019-03-01</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1927</th>\n",
       "      <td>传媒实习 · 广东 | 腾讯、乐逗游戏</td>\n",
       "      <td>2019-03-01</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1930</th>\n",
       "      <td>传媒实习 · 北京 | 网易财经、奥美、 腾讯领投公司 “宝宝玩英语”</td>\n",
       "      <td>2018-07-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1934</th>\n",
       "      <td>传媒实习 · 北京 | 网易财经、奥美、 腾讯领投公司 “宝宝玩英语”</td>\n",
       "      <td>2018-07-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1938</th>\n",
       "      <td>传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...</td>\n",
       "      <td>2018-07-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...</td>\n",
       "      <td>腾讯</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>265 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  title create_time  \\\n",
       "0                       传媒实习 · 鹅厂 | 腾讯运营、视频、产品多岗「北京/广东」  2020-05-15   \n",
       "10                                   传媒实习 · 运营 | 腾讯「北京」  2020-05-14   \n",
       "16                                  传媒实习 · 鹅厂 | 腾讯新闻星推榜  2020-05-13   \n",
       "25                                传媒实习 · 鹅厂 | 腾讯多岗位「广东」  2020-05-12   \n",
       "33                                 传媒实习 · 游戏 | 腾讯游戏「广东」  2020-05-11   \n",
       "...                                                 ...         ...   \n",
       "1926                     传媒实习 · 北京 | CCTV《相聚中国节》、腾讯视频等。  2019-03-01   \n",
       "1927                                传媒实习 · 广东 | 腾讯、乐逗游戏  2019-03-01   \n",
       "1930                传媒实习 · 北京 | 网易财经、奥美、 腾讯领投公司 “宝宝玩英语”  2018-07-19   \n",
       "1934                传媒实习 · 北京 | 网易财经、奥美、 腾讯领投公司 “宝宝玩英语”  2018-07-19   \n",
       "1938  传媒实习 · 北京 | 北京万博宣伟公关公司、环球网、腾讯视频、猫眼电影、不二、腾讯、VOG...  2018-07-10   \n",
       "\n",
       "                                                   link variable  \n",
       "0     http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       鹅厂  \n",
       "10    http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "16    http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       鹅厂  \n",
       "25    http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       鹅厂  \n",
       "33    http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "...                                                 ...      ...  \n",
       "1926  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "1927  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "1930  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "1934  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "1938  http://mp.weixin.qq.com/s?__biz=MzI1ODcxNzMxMQ...       腾讯  \n",
       "\n",
       "[265 rows x 4 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_o[df_o.title.str.contains(\"腾讯\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>variable</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>无法分类</th>\n",
       "      <td>1586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>腾讯</th>\n",
       "      <td>203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>鹅厂</th>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>出行</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>微信</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>城市</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>智库</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>未来</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>数据</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>疫情</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>QQ</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>平台</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>联合国</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>武汉</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>图片</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>基金</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>开放</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>智能</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          title\n",
       "variable       \n",
       "无法分类       1586\n",
       "腾讯          203\n",
       "鹅厂           88\n",
       "出行           11\n",
       "微信            8\n",
       "城市            7\n",
       "智库            6\n",
       "未来            6\n",
       "数据            5\n",
       "疫情            5\n",
       "QQ            5\n",
       "平台            3\n",
       "联合国           3\n",
       "武汉            2\n",
       "图片            2\n",
       "基金            1\n",
       "开放            1\n",
       "智能            1"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_stats = df_o.groupby(by=\"variable\").agg({\"title\":\"count\"}).sort_values(by=\"title\", ascending=False)\n",
    "df_stats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_account.columns.name = \"rel_accounts\"\n",
    "df_o.columns.name = \"url_cat\"\n",
    "df_stats.columns.name = \"stats\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "_df_.columns.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the xlsxwriter workbook and worksheet objects.  \n",
    "with pd.ExcelWriter(\"传媒实习那些事儿.xlsx\") as writer:\n",
    "    workbook  = writer.book\n",
    "\n",
    "    for _df_ in [df_account, df_o, df_stats]:\n",
    "        _df_.to_excel(writer, sheet_name = _df_.columns.name)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
